package com.ruoyi.safe.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.BizRectifyReview;
import com.ruoyi.safe.domain.CommonProject;
import com.ruoyi.safe.domain.dto.ProjectSearchDTO;
import com.ruoyi.safe.domain.vo.CommonProjectVO;
import com.ruoyi.safe.service.ICommonProjectService;
import com.ruoyi.system.domain.vo.UserMessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 项目管理Controller
 * 
 * @author buxi
 * @date 2023-11-08
 */
@RestController
@RequestMapping("/common/project")
public class CommonProjectController extends BaseController
{
    @Autowired
    private ICommonProjectService commonProjectService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('common:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectSearchDTO projectSearch)
    {
        startPage();
        List<CommonProjectVO> list = commonProjectService.selectCommonProjectList(projectSearch);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('common:project:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectSearchDTO projectSearch)
    {
        List<CommonProject> list = commonProjectService.selectCommonProjectListExcel(projectSearch);
        ExcelUtil<CommonProject> util = new ExcelUtil<CommonProject>(CommonProject.class);
        util.exportExcel(response, list, "项目管理数据");
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commonProjectService.selectCommonProjectById(id));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('common:project:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonProject commonProject)
    {
        return toAjax(commonProjectService.insertCommonProject(commonProject));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('common:project:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonProject commonProject)
    {
        return toAjax(commonProjectService.updateCommonProject(commonProject));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('common:project:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commonProjectService.deleteCommonProjectByIds(ids));
    }

    /**
     * 查询自己所在项目列表和下级部门签约项目列表
     */
    @GetMapping("/in/project")
    public AjaxResult selInProjectList()
    {
        return success(commonProjectService.selInProjectList());
    }

    /**
     * 项目精简列表
     */
    @GetMapping("/simpleObjectList")
    public List<Map<String,Object>> simpleObjectList(CommonProject commonProject){
        return commonProjectService.getSimpleObjectList(commonProject);
    }

    /**
     * 查询移交人
     */
    @GetMapping("/transferUser")
    public AjaxResult transferUser(Long projectId) {
        List<UserMessageVO> userMessageVOS = commonProjectService.transferUser(projectId);
        return success(userMessageVOS);
    }

    /**
     * 整改移交
     */
    @PostMapping("/transfer")
    public AjaxResult transfer(@RequestBody BizRectifyReview bizRectifyReview) {
        return toAjax(commonProjectService.insertBizRectifyReview(bizRectifyReview));
    }
}
